//
//  SettingViewController.swift
//  XiaoXiangMu1604
//
//  Created by qianfeng on 16/9/29.
//  Copyright © 2016年 SunPiaoLiang. All rights reserved.
//

import UIKit

class SettingViewController: LFNavigationViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //创建导航
        cteateNav()
    
        //创建APP图像按钮
        createBtns()
        
    }
    
    func cteateNav(){
        
        addBackButton()
        
        addNavTitle("设置")
        
        
    }
    func createBtns(){
    
    
        let imageArray = ["account_setting","account_favorite","account_user","account_collect","account_download","account_comment","account_help","account_candou"]
        
        let titleArray = ["我的设置","我的关注","我的账号","我的收藏","我的下载","我的评论","我的帮助","蚕豆应用"]
    
        //循环创建按钮
        let colNum = 3 //列数
        
        let btnW:CGFloat = 80 //按钮的宽度
        
        let btnH:CGFloat = 80//按钮的高度
        
        let tilH:CGFloat = 20 //文字的高度
        
        let offsetX:CGFloat = 40 //第一行按钮左边的间距
        
        let offsetY:CGFloat = 160 //第一行按钮的Y值
        
        let spaceX:CGFloat = (KScreenWidth-offsetX*2-btnW*CGFloat(colNum))/(CGFloat(colNum)-1) //按钮之间的列间距
        
        let spaceY:CGFloat = 50//按钮之间的行间距
        
        for i in 0..<imageArray.count{
            
            let row = i / colNum
            
            let col = i % colNum
            
            let btnX = offsetX + (btnW + spaceX) * CGFloat(col)
            
            let btnY = offsetY + (btnH + tilH + spaceY) * CGFloat(row)
            
            let btn = UIButton.createBtn(CGRectMake(btnX,btnY,btnW,btnH), title:nil, bgImageName: imageArray[i], target: self, action: "clickBtn:")
            
            btn.tag = 200+i
            
            view.addSubview(btn)
            
            //文字
            let label = UILabel.createLabelFrame(CGRectMake(btnX,btnY+btnH,btnW,tilH), title: titleArray[i], textAlignment: .Center)
            
            label.font = UIFont.systemFontOfSize(15)
            
            view.addSubview(label)
            
        }
        
    
    }
    func clickBtn(btn:UIButton){
        
        let index = btn.tag - 200
        
        print(index)
        
        if index == 3{
            
            let collectCtl = CollectViewController()
            
            hidesBottomBarWhenPushed = true
            
            navigationController?.pushViewController(collectCtl, animated: true)
            
        }
        
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
